package class1;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class demo1 {
    public static void main1(String[] args) {
        HashMap<Integer,String>hashMap=new HashMap<>();

        hashMap.put(1,"张三");
        hashMap.put(2,"李四");
        hashMap.put(3,"王五");
        System.out.println("1:"+hashMap.get(1));
        System.out.println("2:"+hashMap.get(2));
        System.out.println("3:"+hashMap.get(3));
        System.out.println(hashMap);
    }


    public static void main2(String[] args) {
        HashMap<Integer,String>hashMap=new HashMap<>();
        hashMap.put(1,"张三");
        hashMap.put(2,"李四");
        hashMap.put(3,"王五");

        Set keySet=hashMap.keySet();
        Iterator iterator= keySet.iterator();
        while (iterator.hasNext()){
            Integer key= (Integer) iterator.next();
            System.out.println(key+":"+hashMap.get(key));
        }
    }

    public static void main(String[] args) {

        HashMap<Integer,String>hashMap=new HashMap<>();
        hashMap.put(1,"张三");
        hashMap.put(2,"李四");
        hashMap.put(3,"王五");
    Set entrySet=hashMap.entrySet();
        Iterator iterator= entrySet.iterator();
        while (iterator.hasNext()){
            Map.Entry entry= (Map.Entry) iterator.next();
            System.out.println(entry.getKey()+" :" +entry.getValue());
        }



    }
    


}
